<template>
    <div>
        <el-dialog :title="treeList.title" :visible.sync="treeList.isShow">
            <el-form :model="dialogInfo" label-width="80px" :rules="formRules">
                <el-form-item label="用户名">
                    <el-input v-model="dialogInfo.username" :disabled="isHandler" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="密码" v-if="!isHandler">
                    <el-input v-model="dialogInfo.password" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="邮箱">
                    <el-input v-model="dialogInfo.email" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="手机">
                    <el-input v-model="dialogInfo.mobile" autocomplete="off"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="treeList.isShow">取 消</el-button>
                <el-button type="primary" @click="queryuserForm">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { addUserApi } from '@/api/user';
export default {
    name: 'MyAppTableTree',
    props: {
        treeList: {
            request: true
        },
        isHandler: {
            default: true
        }
    },
    data() {
        return {
            dialogInfo: {
                username: "",
                password: "",
                email: "",
                mobile: ""
            },
            formRules: {
                username: [
                    { required: "true", message: "请输入用户号", trigger: "blur" }
                ],
                password: [
                    { required: "true", message: "请输入密码", trigger: "blur" }
                ],
                email: [
                    { required: "true", message: "请输入邮箱", trigger: "blur" }
                ],
                mobile: [
                    { required: "true", message: "请输入手机号", trigger: "blur" }
                ]
            }
        };
    },

    mounted() {

    },

    methods: {
        // 添加方法
        async queryuserForm() {
            if (this.treeList.options == 'add') {
                try {
                    await addUserApi(this.dialogInfo)
                    this.$message.success('添加成功')
                } catch (error) {
                    this.$message.error('添加失败')
                }
            }
            this.dialogInfo = {
                username: "",
                password: "",
                email: "",
                mobile: ""
            }
            this.treeList.isShow=false
        }
    },
};
</script>

<style lang="scss" scoped>

</style>